package org.muninn.niagara.structures;

import javax.baja.sys.BComponent;
import javax.baja.sys.Type;

public class BPointNode extends BPointTreeNode
{
  private BMode[] children = new BMode[8];
  
  public BPointNode(BComponent comp) { super(comp); }
  
  public void addMode(String name, String value, String num)
  {
    BMode mode;
    
    if (this.getType().toString().toLowerCase().indexOf("numeric") != -1)
      mode = new BNumMode(name, value, num);
    
    else if (this.getType().toString().toLowerCase().indexOf("boolean") != -1)
      mode = new BBoolMode(name, value, num);
    
    else if (this.getType().toString().toLowerCase().indexOf("enum") != -1)
      mode = new BEnumMode(name, value, num);
    
    else
      return;
    
    if (this.children[Integer.parseInt(num)] == null)
      this.children[Integer.parseInt(num)] = mode;
    
    else
    {
      for (int i = 0; i < this.children.length; i++)
      {
        if (this.children[i] == null)
        {
          this.children[i] = mode;
          return;
        }
      }
      
      BMode[] temp = new BMode[this.children.length * 2];
      for (int i = 0; i < this.children.length; i++)
        temp[i] = this.children[i];
      
      temp[this.children.length] = mode;
      this.children = temp;
    }
  }
  
  public BMode[] getModes() { return this.children; }
  
  public Type getType() { return this.realObj.getType(); }
}
